生命周期

生命周期

time:26_1_17

析构

1.{}范围内进行释放
2.如果没有保存;结束后释放

左指右值

& 左指 ;结束后释放
&& 右指所有权,不会随意释放

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# include <iostream>
# include <utilty>

class Mystring{
private:
char *data;
public:
Mystring(const char *str = ""){
data = new char[strlen(str)+1];
strcpy(data, str);
}
~Mystring*(){
delete[] data;
}
// 移动构造
Mystring & operatir = (Mystring && other){
if(other.data != this.data){
data = other.data;
other.data = nullptr;
}
return this;
}

}